﻿using System;
using Assets.Scripts.GtsScripts;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x020003A7 RID: 935
public class MorphsView : MonoBehaviour
{
	// Token: 0x06001892 RID: 6290 RVA: 0x0009B064 File Offset: 0x00099264
	private void Start()
	{
		this.control = Camera.main.GetComponent<InterfaceControl>();
		Button[] componentsInChildren = base.GetComponentsInChildren<Button>();
		componentsInChildren[0].onClick.AddListener(delegate()
		{
			this.OnPrevious();
		});
		componentsInChildren[1].onClick.AddListener(delegate()
		{
			this.OnNext();
		});
		componentsInChildren[2].onClick.AddListener(delegate()
		{
			this.OnApply();
		});
		this.placeholder = (Resources.Load("UI/Button/FieldSlider") as GameObject);
		this.grid = base.GetComponentInChildren<GridLayoutGroup>();
		RectTransform component = this.grid.GetComponent<RectTransform>();
		int num = (int)component.rect.height / 30;
		this.elementsCount = num;
		this.text = new Text[this.elementsCount];
		this.slider = new Slider[this.elementsCount];
		for (int i = 0; i < this.elementsCount; i++)
		{
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.placeholder, this.grid.transform);
			gameObject.name = "Slider " + i;
			this.text[i] = gameObject.GetComponentInChildren<Text>();
			this.slider[i] = gameObject.GetComponentInChildren<Slider>();
			int number = i;
			this.slider[i].onValueChanged.AddListener(delegate(float val)
			{
				this.OnValueChanged(number, val);
			});
		}
		this.control.OnSelected += this.OnChangedCharacter;
		base.gameObject.SetActive(false);
	}

	// Token: 0x06001893 RID: 6291 RVA: 0x0009B202 File Offset: 0x00099402
	private void OnChangedCharacter()
	{
		if (base.gameObject.activeSelf)
		{
			this.ReloadValues();
		}
	}

	// Token: 0x06001894 RID: 6292 RVA: 0x0009B21A File Offset: 0x0009941A
	private void OnEnable()
	{
		this.ReloadValues();
	}

	// Token: 0x06001895 RID: 6293 RVA: 0x0009B224 File Offset: 0x00099424
	private void ReloadValues()
	{
		if (this.control == null)
		{
			return;
		}
		if (this.control.giantess == null)
		{
			base.gameObject.SetActive(false);
			return;
		}
		this.morphs = this.control.GetMorphList();
		if (this.morphs == null)
		{
			return;
		}
		this.page = 0;
		this.pageCount = this.morphs.Length / this.elementsCount + 1;
		this.LoadPage(this.page);
	}

	// Token: 0x06001896 RID: 6294 RVA: 0x0009B2B0 File Offset: 0x000994B0
	private void OnValueChanged(int i, float value)
	{
		int i2 = this.page * this.elementsCount + i;
		this.control.SetMorph(i2, value);
	}

	// Token: 0x06001897 RID: 6295 RVA: 0x0009B2DC File Offset: 0x000994DC
	private void LoadPage(int pag)
	{
		int num = pag * this.elementsCount;
		for (int i = 0; i < this.elementsCount; i++)
		{
			int num2 = num + i;
			if (num2 < this.morphs.Length)
			{
				this.text[i].text = this.morphs[num2].Name;
				this.slider[i].value = this.morphs[num2].Weight;
				this.text[i].transform.parent.gameObject.SetActive(true);
			}
			else
			{
				this.text[i].transform.parent.gameObject.SetActive(false);
			}
		}
	}

	// Token: 0x06001898 RID: 6296 RVA: 0x0009B396 File Offset: 0x00099596
	private void OnNext()
	{
		this.page++;
		if (this.page >= this.pageCount)
		{
			this.page = 0;
		}
		this.LoadPage(this.page);
	}

	// Token: 0x06001899 RID: 6297 RVA: 0x0009B3CA File Offset: 0x000995CA
	private void OnDisable()
	{
		if (this.control)
		{
			this.control.UpdateCollider();
		}
	}

	// Token: 0x0600189A RID: 6298 RVA: 0x0009B3E7 File Offset: 0x000995E7
	private void OnPrevious()
	{
		this.page--;
		if (this.page < 0)
		{
			this.page = this.pageCount - 1;
		}
		this.LoadPage(this.page);
	}

	// Token: 0x0600189B RID: 6299 RVA: 0x0009B41D File Offset: 0x0009961D
	private void OnApply()
	{
		this.control.UpdateCollider();
	}

	// Token: 0x04001AA9 RID: 6825
	private Giantess.MorphData[] morphs;

	// Token: 0x04001AAA RID: 6826
	private GameObject placeholder;

	// Token: 0x04001AAB RID: 6827
	private int elementsCount;

	// Token: 0x04001AAC RID: 6828
	private GridLayoutGroup grid;

	// Token: 0x04001AAD RID: 6829
	private InterfaceControl control;

	// Token: 0x04001AAE RID: 6830
	private int page;

	// Token: 0x04001AAF RID: 6831
	private int pageCount;

	// Token: 0x04001AB0 RID: 6832
	private Text[] text;

	// Token: 0x04001AB1 RID: 6833
	private Slider[] slider;
}
